﻿using System.Net.DnsToolkit.Packet;
using System.Net.DnsToolkit.Packet.Records;

namespace System.Net.DnsToolkit.Serializer {
    /// <summary>
    /// Reads a TRecord from source. QTypeEnum will defined if the 
    /// RecordReader is of good type.
    /// </summary>
    /// <typeparam name="TRecord"></typeparam>
    /// <typeparam name="T"></typeparam>
    public interface IRecordReader<T> {

        /// <summary>
        /// QTypeEnum determines the type of record that will be read by the reader.
        /// eg. QTypeEnum.A creates RecordA, QTypeEnum.AAAA creates RecordAAAA
        /// </summary>
        /// <param name="qTypeEnum"></param>
        /// <returns></returns>
        QTypeEnum QTypeEnum { get; }

        /// <summary>
        /// Reads TRecord from source, throws Exception if error occurs
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        IRecord Read(T source);

        /// <summary>
        /// Reads TRecord from source, try not to throws Exception if error occurs
        /// </summary>
        /// <param name="source"></param>
        /// <param name="record"></param>
        /// <returns>true if IRecord successfully read</returns>
        bool TryRead(T source, out IRecord record);


    }
}
